var root = {
  val: 1,
  right: {
    val: 2,
    left: {
      val: 3
    }
  }
}

/**
 * 实现的动态过程是
 * https://leetcode-cn.com/problems/binary-tree-preorder-traversal/solution/er-cha-shu-de-qian-xu-bian-li-by-leetcode-solution/
 * @param {TreeNode} root
 * @return {number[]}
 */
var inorderTraversal = function(root) {
  var res = [];
  function traversal (node) {
    if (!node) {
      return
    }
    traversal(node.left);
    res.push(node.val);
    traversal(node.right);
  }
  traversal(root);
  return res;
};

console.log(inorderTraversal(root))